#include<stdio.h>
#include<queue>
using namespace std;
priority_queue<long long,vector<long long>,greater<long long> > q;
int main()
{
	int n,p;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&p);
		q.push(p);
	}
	long long x,y,sum=0;
	while(q.size()>1){
		x=q.top();
		q.pop();
		y=q.top();
		q.pop();
		q.push(x+y);
		sum+=x+y;		
	}
	printf("%lld",sum);
	return 0;
}
